##
# Map
#
# Description: This file contains the Map Object
#

from Tile import *
from Coodinate import *

class Map:

    def __init__(self):

        # A list of all the entities on the map
        self.allEntities = []

        self.tiles = None

        return

    ##
    # addEntity
    #
    # Description: adds a given entity to the map at the given position
    #
    # Parameters:
    #   entity - the entity to add to the map
    #   position - where to add the entity. If not attribute given then will use the entities position.
    #       However if a position is given then it will set the entities position and place the tile there
    #   stackPosition - the location on the tile stack to place the entity. Defaults to the top tile
    ##
    def addEntity(self, entity, position=None, stackPosition=-1):

        self.allEntities.append(entity)

        if position:
            entity.position = position

        tile = self.getTile(entity.position)
        tile.addEntity(entity, stackPosition=stackPosition, touchStack=False)

    ##
    # removeEntity
    #
    # Description: removes a given entity to the map
    #
    # Parameters:
    #   entity - the entity to add to the map
    ##
    def removeEntity(self, entity):

        self.allEntities.remove(entity)

        tile = self.getTile(entity.position)
        tile.removeEntity(entity)


    ##
    # getTile
    #
    # Description: Gets the tile at the given position
    #
    # Parameters:
    #   position - the position on the map to get the tile from
    #
    # Returns: the tile at the given position
    ##
    def getTile(self, position):
        x = position.x
        y = position.y
        return self.tiles[x][y]

    ##
    # generateMap
    #
    # Description: generates the map for first time setup
    def generateMap(self, width, height):
        from mapGenerationUtilities import genereate

        self.width = width
        self.height = height
        genereate(self)



import ViewPort
import libtcodpy as libtcod


# # Include a custom font
# libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
#
# # Initialize the window (widthl, height, title, isFullscreen)
# libtcod.console_init_root(10, 10, 'Eldritch Dungeons', False)


m = Map()
m.generateMap(200, 200)


vp = ViewPort.ViewPort(100, 40, m)


# Create a new console for graphics buffering
con = libtcod.console_new(vp.width, vp.height)


# Include a custom font
libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)

# Initialize the window (widthl, height, title, isFullscreen)
libtcod.console_init_root(vp.width, vp.height, 'Eldritch Dungeons', False)

# Limit the frames per second for a real-time roguelike
libtcod.sys_set_fps(20)


while not libtcod.console_is_window_closed():
    vp.draw(con, m)
    libtcod.console_flush()

    vp.handleInput()

